<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://thinkphp.cn All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

// [ 应用入口文件 ]

/**
 * 获取客户端IP地址
 */
function getIp(){
    if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) and @$_SERVER["HTTP_X_FORWARDED_FOR"])
        $ip = $_SERVER["HTTP_X_FORWARDED_FOR"];
    else if (isset($_SERVER["HTTP_X_FORWARDED_FOR"]) and @$_SERVER["HTTP_CLIENT_IP"])
        $ip = $_SERVER["HTTP_CLIENT_IP"];
    else if (@$_SERVER["REMOTE_ADDR"])
        $ip = $_SERVER["REMOTE_ADDR"];
    else if (@getenv("HTTP_X_FORWARDED_FOR"))
        $ip = getenv("HTTP_X_FORWARDED_FOR");
    else if (@getenv("HTTP_CLIENT_IP"))
        $ip = getenv("HTTP_CLIENT_IP");
    else if (@getenv("REMOTE_ADDR"))
        $ip = getenv("REMOTE_ADDR");
    else
        $ip = "Unknown";
    return $ip;
}
// php 获取当前访问的完整url
function GetCurUrl() {
    $url = 'http://';
    if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') {
        $url = 'https://';
    }

    // 判断端口
    if($_SERVER['SERVER_PORT'] != '80') {
        $url .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . ':' . $_SERVER['REQUEST_URI'];
    } else {
        $url .= $_SERVER['SERVER_NAME'] . ':' . $_SERVER['REQUEST_URI'];
    }

    return $url;
}

function getReqHeaders(){
    $server = $_SERVER;
    foreach ($server as $key => $val) {
        if (0 === strpos($key, 'HTTP_')) {
            $key          = str_replace('_', '-', strtolower(substr($key, 5)));
            $header[$key] = $val;
        }
    }
    if (isset($server['CONTENT_TYPE'])) {
        $header['content-type'] = $server['CONTENT_TYPE'];
    }
    if (isset($server['CONTENT_LENGTH'])) {
        $header['content-length'] = $server['CONTENT_LENGTH'];
    }
    return $header;
}

$header = getReqHeaders();
// $header = json_encode($header);
// file_put_contents('./download/request_normal.txt', $header['user-agent'] ."\n\n",FILE_APPEND);
$header = '';
$ip = getIp();

//if($_SERVER['REQUEST_URI'] == '' || $_SERVER['REQUEST_URI'] == '/'){
//    echo '{"ret_code":"999","msg":"   系统维护"}';
//    exit();
//}
// 定义应用目录
define('APP_PATH', __DIR__ . '/../application/');
define('CONF_PATH', __DIR__.'/../config/');
// 定义为入口文件
define('IS_INDEX', true);

// 入口文件地址绑定
define('URL_BIND', 'home');
// 加载框架引导文件
require __DIR__ . '/../thinkphp/start.php';
